<?php

namespace App\View\Helper;

use Cake\View\Helper;

class LinkHelper extends Helper {

    public $helpers = ['Url'];

    public function returnUrl(array $url, $full = NULL) {
        $params = $this->request->query;
        if (isset($params['returnUrl'])) {
            return $params['returnUrl'];
        }

        return $this->Url->build($url, $full);
    }

    public function urlWithReturnUrl(array $url = NULL, $full = NULL) {
        if ($url == null) {
            $url = array('?' => ['returnUrl' => $this->request->here()]);
        } else if (!isset($url['?'])) {
            $url['?'] = ['returnUrl' => $this->request->here()];
        } else {
            array_push($url['?'], ['returnUrl' => $this->request->here()]);
        }

        if ($full == null) {
            $full = false;
        }

        return $this->Url->build($url, $full);
    }

}
